# James Hollyer
# January 25, 2010
# Purpose: To match panels of autocratic countries that sign the CAT to those 
# that do not.
# Data Input: For_Matching.dta
# Data Output: Matched.dta

# Set the working directory to that used for the PTA paper.
setwd("C:/Documents and Settings/James/Desktop/My Dropbox/Collaboration with Peter")

# Load the Necessary Packages
library(arm)
library(MatchIt)
library(Matching)
library(foreign)

# Read the data into R
ptas <- read.dta("baccini_collapsed.dta")
attach(ptas)

# The following will run a genetic matching algorithm on the collapsed Baccini
# data and will run matching diagnostics.
matchptas <- matchit(pta_lead_sign ~ polity2 + rgdpch + openk + grgdpch, data=ptas, method="nearest", replace=FALSE, caliper=.5)


summary(matchptas)
matchptas$match.matrix

plot(matchptas, type="jitter")
plot(matchptas, type="hist")
plot(matchptas, type="QQ")
summary(matchptas)

matchPTAs<-match.data(matchptas)

write.dta(matchPTAs, file="baccinimatched2.dta")
